package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.GuestsCarEditResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.GuestsCar;
import com.yh.homestay.service.GuestsCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName GuestsCarController
 * @Description 车辆Controller
 * @Date 2020/1/13 15:50
 */
@RestController
@Api(description = "车辆管理")
@RequestMapping(value = "/car")
public class GuestsCarController {

    @Autowired
    private GuestsCarService guestsCarService;

    /**
     * @param page
     * @param limit
     * @param carType
     * @Date: 2020/1/13 16:14
     * @Description: 查看车辆列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @SystemLog(methods = "查看车辆列表", module = "车辆管理")
    @ApiOperation(value = "获取所有车辆列表", notes = "获取所有车辆信息或者模糊查询")
    public HomeStayResult selectAll(Integer page, Integer limit, String carType) {
        HomeStayResult resultMessage = guestsCarService.selectAll(page, limit, carType);
        return resultMessage;
    }

    /**
     * @param guestsCar
     * @Date: 2020/1/13 16:14
     * @Description: 添加车辆信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SystemLog(methods = "添加车辆信息", module = "车辆管理")
    @ApiOperation(value = "添加车辆", notes = "添加车辆信息")
    public HomeStayResult addCar(GuestsCar guestsCar) {
        HomeStayResult homStayResult = guestsCarService.addCar(guestsCar);
        return homStayResult;
    }

    /**
     * @param id
     * @Date: 2020/1/13 16:14
     * @Description: 回显车辆信息
     * @return: com.yh.homestay.common.GuestsCarEditResult
     */
    @RequestMapping(value = "/selectOne/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "回显车辆信息", notes = "根据id回显车辆信息")
    public GuestsCarEditResult editcar(@PathVariable String id) {
        return guestsCarService.selectone(id);
    }

    /**
     * @param guestsCar
     * @Date: 2020/1/13 16:14
     * @Description: 修改车辆信息
     * @return: com.yh.homestay.common.GuestsCarEditResult
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SystemLog(methods = "修改车辆信息", module = "车辆管理")
    @ApiOperation(value = "修改车辆信息", notes = "修改车辆信息")
    public GuestsCarEditResult updateCar(GuestsCar guestsCar) {
        return guestsCarService.updateGuestsCar(guestsCar);
    }


    /**
     * @param carId
     * @Date: 2020/1/13 16:14
     * @Description: 删除车辆信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @SystemLog(methods = "删除车辆", module = "车辆管理")
    @ApiOperation(value = "删除车辆", notes = "删除车辆信息")
    public HomeStayResult deleteById(@PathVariable(value = "id") String carId) {
        HomeStayResult delete = guestsCarService.delete(carId);
        return delete;
    }

    /**
     * @param ids
     * @Date: 2020/1/13 16:14
     * @Description: 批量删除车辆信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @SystemLog(methods = "删除多个车辆", module = "车辆管理")
    @ApiOperation(value = "批量删除车辆", notes = "批量删除车辆信息")
    public HomeStayResult delete(@RequestParam List<String> ids) {
        HomeStayResult delete = guestsCarService.deleteCarS(ids);
        return delete;
    }

}